/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.snda.lidejia.hivetotalsort.mr;

import com.snda.lidejia.hivetotalsort.type.HiveSortKey;
import java.io.IOException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.compress.CompressionCodecFactory;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileSplit;
import org.apache.hadoop.mapred.InputSplit;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.JobConfigurable;
import org.apache.hadoop.mapred.RecordReader;
import org.apache.hadoop.mapred.Reporter;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;

/**
 *
 * @author lidejia
 */
public class HiveSortFileInputFormat extends FileInputFormat<HiveSortKey, Text> implements JobConfigurable {

    private CompressionCodecFactory compressionCodecs = null;

    @Override
    public void configure(JobConf conf) {
        compressionCodecs = new CompressionCodecFactory(conf);
    }

    protected boolean isSplitable(FileSystem fs, Path filename) {
        //compiled code
        return compressionCodecs.getCodec(filename) == null;
    }

    @Override
    public RecordReader<HiveSortKey, Text> getRecordReader(InputSplit is, JobConf jc, Reporter rprtr) throws IOException {
        return new HiveSortRecordReader(jc, (FileSplit) is);
    }
}
